package com.oig.sys.base.controller;


import com.oig.common.module.SysPageInfo;
import com.oig.common.module.SysRequest;
import com.oig.common.module.SysResponse;
import com.oig.common.validator.GroupAdd;
import com.oig.common.validator.GroupEdit;
import com.oig.sys.base.dto.BankNoDto;
import com.oig.sys.base.service.ITbBankNoService;
import com.oig.sys.base.vo.BankNoVo;
import com.oig.sys.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "行名行号管理")
@RestController
@RequestMapping("/bankNo")
@Slf4j
public class TbBankNoController {

    private final ITbBankNoService bankNoService;

    @Autowired
    public TbBankNoController(ITbBankNoService bankNoService){
        this.bankNoService = bankNoService;
    }

    @PreAuthorize("@pms.hasPermission('/bankNo/addBankNo')")
    @SysLog(value="添加行名行号",apiUrl="/bankNo/addBankNo")
    @Operation(summary = "添加行名行号")
    @PostMapping(value = "/addBankNo")
    public BankNoVo addBankNo(@RequestBody @Validated(GroupAdd.class) BankNoDto bankNoDto){
        log.info("add BankNo {}",bankNoDto);
        return this.bankNoService.addTbBankNo(bankNoDto);
    }

    @PreAuthorize("@pms.hasPermission('/bankNo/updateBankNo')")
    @SysLog(value="修改行名行号",apiUrl="/bankNo/updateBankNo")
    @Operation(summary = "修改行名行号")
    @PostMapping(value = "/updateBankNo")
    public BankNoVo updateBankNo(@RequestBody @Validated(GroupEdit.class) BankNoDto bankNoDto){
        log.info("update BankNo {}",bankNoDto);
        return this.bankNoService.updateTbBankNo(bankNoDto);
    }

    @PreAuthorize("@pms.hasPermission('/bankNo/cancelBankNo')")
    @SysLog(value="逻辑删除行名行号",apiUrl="/bankNo/cancelBankNo")
    @Operation(summary = "逻辑删除行名行号")
    @PostMapping(value = "/cancelBankNo/{bankNo}")
    public SysResponse<String> cancelBankNo(@PathVariable("bankNo") String bankNo){
        log.info("cancel BankNo bankNo={}", bankNo) ;
        this.bankNoService.cancelTbBankNo(bankNo);
        return SysResponse.ok(bankNo,"逻辑删除行名行号成功");
    }


    @Operation(summary = "查询备选行名行号")
    @PostMapping(value = "/findBankNo")
    public SysPageInfo<BankNoVo> findBank(@RequestBody SysRequest<BankNoDto> bankNoRequest){
        log.info("find BankNo {}", bankNoRequest) ;
        return this.bankNoService.findTbBankNo(bankNoRequest) ;
    }

    @Operation(summary = "根据行号查询行名行号")
    @PostMapping(value = "/getByBankNo")
    public List<BankNoVo> getByBankNo(@RequestBody List<String> bankNoList){
        log.info("根据行号查询行名行号 find BankNo {}", bankNoList) ;
        return this.bankNoService.getByBankNo(bankNoList) ;
    }
}
